package zz.note.thread.create;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 使用Callable的形式创建线程
 * @Author: ZZ
 * @date 2022/2/16
 */
public class MyCallable implements Callable<String> {
	public String call() throws Exception {
		System.out.println(Thread.currentThread().getName() + "正在异步调用接口发送短信");
		try {
			Thread.sleep(3000);
		} catch (Exception e) {

		}
		return "短信发送成功";
	}

	public static void main(String[] args) throws ExecutionException, InterruptedException {
		FutureTask<String> futureTask = new FutureTask<String>(new MyCallable());
		Thread thread = new Thread(futureTask);
		thread.start();
		String result = futureTask.get();
		System.out.println(Thread.currentThread().getName() + result);
	}
}